
use "/homeKRTK/health_shocks/data_for_main_regs_event_study_20231203.dta", clear
drop if control==1
append using "/homeKRTK/health_shocks/additional_data_for_all_regs_controls_nod_20240422.dta"
append using "/homeKRTK/health_shocks/additional_data_for_IV_and_placebo_regs_20240416.dta"

keep if control==0
cap drop ABS
gen ABS=0 if d==1
replace ABS=1 if d>=2 & d<=6
keep ABS anon t
save "/homeKRTK/health_shocks/HSanons_20231209_ACC1.dta", replace

use "/homeKRTK/health_shocks/placebo_base_bnoSext_2023Dec.dta", clear

cap drop spend_shock_narrow max_bnoSext B_ft_shock_narrow N_ft_shock_narrow

rename t st

merge m:1 anon using "/homeKRTK/health_shocks/HSanons_20231209_ACC1.dta", nogen keep(master match)

rename t t_shock
rename st t

gen et_max_bnoSext=t-t_shock
	
keep if et_max_bnoSext~=. 
unique anon // Number of unique values of anon is 25767

*bring in detailed sickleave data
merge 1:1 anon t using "/homePCIESSD800/Admin3/Output_data/Alap/admin3_passziv_kieg_H1_v1.dta", nogen keepusing(passziv_ho)

replace passziv_ho=0 if passziv_ho==.

gen sl_relevant1_=passziv_ho if t>=t_shock & t<=t_shock+1
by anon, sort: gegen sl_relevant1=total(sl_relevant1_)
drop sl_relevant1_

keep if sl_relevant1>0

merge 1:1 anon t using "/homeProspSSD/Admin3/admin3_alap.dta", nogen keep(master match) keepusing(transfer_ny transfer_mtp nap ev w1 wh1 nap ho t)

*bring in doctoral visits
merge 1:1 anon t using "/homeProspSSD/Admin3/admin3_eu_jaro.dta", nogen keepusing(jaro_db)  keep(master match) 
merge 1:1 anon t using "/homeProspSSD/Admin3/admin3_eu_hazio.dta", nogen keepusing(hsz_eset) keep(master match) 
foreach var of varlist jaro_db hsz_eset {
	replace `var'=0 if `var'==. & ev>=2009
}
gen dr=jaro_db + hsz_eset


foreach var of varlist A_ft B_ft C_ft J_ft L_ft M_ft N_ft R_ft N05_ft N06_ft {
	cap drop bin_`var'
	gen bin_`var'=0
	replace bin_`var'=1 if `var'>0 & `var'~=.
}

foreach var of varlist A_ft B_ft C_ft J_ft L_ft M_ft N_ft R_ft N05_ft N06_ft {
	replace `var'=0 if `var'==.
}
cap drop total_drug
gen total_drug=A_ft+B_ft+C_ft+D_ft+G_ft+J_ft+L_ft+M_ft+N_ft+R_ft+S_ft+V_ft+ZPV_ft

***Input for Figure 2 - saved in "$folder\EventStudy_27Aug2024.xlsx"
cap erase /homeKRTK/health_shocks/EventStudy/log_EventStudy_health.log
log using /homeKRTK/health_shocks/EventStudy/log_EventStudy_health.log, append

	foreach var of varlist max_bnoSext {

		foreach depvar of varlist hosp5 total_drug passziv_ho bin_J_ft bin_M_ft bin_N06_ft dr {

		table et_`var' ABS if et_`var'>=-24 & et_`var'<=24 & t_shock>=109, stat(mean `depvar')

		}
	}

log close
